package model;

import java.util.Collection;
import java.util.Vector;

public abstract class Observable {
	private final Collection<Observer> observers;
	
	/**
	 * Constructor of {@link Observable}.
	 */
	public Observable(){
		this.observers = new Vector<Observer>();
		
	}
	/**
	 * Provides true when no {@link Observer}s are registered.
	 * @return true when no {@link Observer}s are registered. Else false.
	 */
	public boolean areObserversEmpty(){
		return this.observers.isEmpty();
	}
	
	/**
	 * Registers an {@link Observer}.
	 * @param o is the registered Observer.
	 */
	public void register(final Observer o){
		this.observers.add(o);
	}
	/**
	 * Deregisters an {@link Observer}.
	 * @param o is the deregistered Observer.
	 */
	public void deregister(final Observer o){
		
		this.observers.remove(o);
	}
	
	/**
	 * Notifies all {@link Observer}s.
	 */
	public void notifyObservers(){
		for(final Observer o : this.observers) o.update();
		this.observers.clear();
	}
}
